const promise = new Promise((resolve, reject) => {
    setTimeout(() => {
        console.log('Async task complete');
        resolve();
    }, 1000);
});
promise.then(() => {
    console.log('Promise consumed...');
});

// new Promise((resolve, reject) => {
//     setTimeout(() => {
//         resolve({ name: 'John', age: 30 });
//     }, 1000);
// }).then((user) => console.log(user));

const getUser = new Promise((resolve, reject) => {
    setTimeout(() => {
        let error = true;
        if (!error) {
            resolve({ name: 'John', age: 30 });
        } else {
            reject('Error:Something went wrong');
        }
    }, 1000);
});

getUser
    .then((user) => console.log(user))
    .catch((error) => console.log(error))
    .finally(() => console.log('The promise has been resolved or rejected'));

console.log('Hello from global scope');
